package com.gq.webstore.hdzw.model;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

import java.util.LinkedList;
import java.util.List;

@Data
public class Chapter {
    private final StringBuilder content = new StringBuilder(8000);
    List<ChapterPage> pageList = new LinkedList<>();
    private int idx;
    private String name;
    private String url;
    private boolean notComplete=false;

    public void setNotComplete(boolean f){
        this.notComplete=f;
    }

    public void appendPage(String url, String content, String orgContent) {
        ChapterPage page = new ChapterPage();
        page.setUrl(url);
        page.setIdx(pageList.size());
        page.setContent(content);
        page.setOrgContent(orgContent);
        pageList.add(page);
        appendContent(content);
    }

    public void appendContent(String con) {
        if (StrUtil.isEmpty(con)) {
            return;
        }
        if (content.length() < 1) {
            content.append(con);
            return;
        }
        if (content.charAt(content.length() - 1) == '\n' || con.startsWith("\n")) {
            content.append(con);
        } else {
            content.append("\n").append(con);
        }
    }

    public int getCharLen() {
        return content.length();
    }
}
